
#include "OpenGL.h"

PFNGLWEIGHTFVARBPROC		glWeightfvARB;
PFNGLWEIGHTPOINTERARBPROC	glWeightPointerARB;
PFNGLVERTEXBLENDARBPROC		glVertexBlendARB;

PFNGLVERTEXATTRIB1FARBPROC glVertexAttrib1fARB;
PFNGLVERTEXATTRIB2FARBPROC glVertexAttrib2fARB;
PFNGLVERTEXATTRIB3FARBPROC glVertexAttrib3fARB;
PFNGLVERTEXATTRIB4FARBPROC glVertexAttrib4fARB;
PFNGLVERTEXATTRIBPOINTERARBPROC glVertexAttribPointerARB;
PFNGLENABLEVERTEXATTRIBARRAYARBPROC glEnableVertexAttribArrayARB;
PFNGLDISABLEVERTEXATTRIBARRAYARBPROC glDisableVertexAttribArrayARB;
PFNGLBINDATTRIBLOCATIONARBPROC glBindAttribLocationARB;
PFNGLGETACTIVEATTRIBARBPROC glGetActiveAttribARB;
PFNGLGETATTRIBLOCATIONARBPROC glGetAttribLocationARB;

PFNGLLOCKARRAYSEXTPROC  glLockArraysEXT;
PFNGLUNLOCKARRAYSEXTPROC   glUnlockArraysEXT;

PFNGLACTIVETEXTUREARBPROC       glActiveTextureARB;
PFNGLCLIENTACTIVETEXTUREARBPROC     glClientActiveTextureARB;
PFNGLMULTITEXCOORD2FARBPROC glMultiTexCoord2fARB;
PFNGLMULTITEXCOORD2FVARBPROC glMultiTexCoord2fvARB;
PFNGLMULTITEXCOORD3FARBPROC glMultiTexCoord3fARB;
PFNGLMULTITEXCOORD3FVARBPROC glMultiTexCoord3fvARB;

PFNGLUNIFORM1FPROC glUniform1f;
PFNGLUNIFORM2FPROC glUniform2f;
PFNGLUNIFORM3FPROC glUniform3f;
PFNGLUNIFORM4FPROC glUniform4f;
PFNGLUNIFORM1IPROC glUniform1i;
PFNGLUNIFORM1UIEXTPROC glUniform1uiEXT;

PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB;
PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB;
PFNGLSHADERSOURCEARBPROC glShaderSourceARB;
PFNGLCOMPILESHADERARBPROC glCompileShaderARB;
PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB;
PFNGLGETINFOLOGARBPROC glGetInfoLogARB;
PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB;
PFNGLATTACHOBJECTARBPROC glAttachObjectARB;
PFNGLLINKPROGRAMARBPROC glLinkProgramARB;
PFNGLDELETEOBJECTARBPROC glDeleteObjectARB;
PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation;
PFNGLUNIFORMMATRIX2FVPROC glUniformMatrix2fvARB;
PFNGLUNIFORMMATRIX3FVPROC glUniformMatrix3fvARB;
PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fvARB;

void GL_GetModelViewMatrix( GLmat4f& m )
{
	glGetFloatv(GL_MODELVIEW_MATRIX, m.Base());
}

void GL_GetViewport( GLvec4f& vp )
{
	glGetFloatv( GL_VIEWPORT, vp.Base());
}

void GL_GetProjectMatrix( GLmat4f& m )
{
	glGetFloatv(GL_PROJECTION_MATRIX, m.Base());
}

void GL_GetPosVec( GLmat4f& m, GLvec3f& pos )
{
	pos.x = -m.w.x;
	pos.y = -m.w.y;
	pos.z = -m.w.z;
}

void GL_GetUpVec( GLmat4f& m, GLvec3f& up )
{
	up[0] = m[0][1];
    up[1] = m[1][1];
    up[2] = m[2][1];
}

void GL_GetRightVec( GLmat4f& m, GLvec3f& right )
{
	right[0] = m[0][0];
    right[1] = m[1][0];
    right[2] = m[2][0];
}

void GL_GetForwardVec( GLmat4f& m , GLvec3f& forward )
{
	forward[0] = m[0][2];
    forward[1] = m[1][2];
    forward[2] = m[2][2];
}

void GL_BeginArray( GLvec3f* pos,GLvec3f*nrm,GLvec2f*tc,GLvec4f*vc)
{
	glEnableClientState( GL_VERTEX_ARRAY );
	
	if( pos){
		
		glVertexPointer( 3,GL_FLOAT,0,&pos->x );

		if( nrm ){
			glEnableClientState( GL_NORMAL_ARRAY );
			glNormalPointer( GL_FLOAT,0,&nrm->x );
		}
		else{
			glDisableClientState( GL_NORMAL_ARRAY );
			
		}

		if( tc){
			glEnableClientState(GL_TEXTURE_COORD_ARRAY);
			glTexCoordPointer( 2,GL_FLOAT,0,&tc->x );		
		}
		else
		{
			glDisableClientState(GL_TEXTURE_COORD_ARRAY);
		}

		if( vc){
			glEnableClientState(GL_COLOR_ARRAY);
			glColorPointer( 4,GL_FLOAT,0,&vc->x );	
		}
		else{
			glDisableClientState(GL_COLOR_ARRAY);
		}
	}
}

void GL_DrawTriListArray( unsigned int* indices,int size )
{
	glDrawElements( GL_TRIANGLES,size,GL_UNSIGNED_INT,indices );	
}

void GL_DrawTriStripArray( unsigned int* indices,int size )
{
	glDrawElements( GL_TRIANGLE_STRIP,size,GL_UNSIGNED_INT,indices );	
}

void GL_EndArray()
{
	glDisableClientState( GL_VERTEX_ARRAY );
	glDisableClientState( GL_NORMAL_ARRAY );
	glDisableClientState( GL_TEXTURE_COORD_ARRAY );
	glDisableClientState( GL_COLOR_ARRAY );
}
